<?php

namespace app\admin\model\outhouse;

use app\admin\model\information\Shelves;
use app\admin\model\information\Warehouse;
use think\Db;
use think\Model;
use traits\model\SoftDelete;

class RdinrecordList extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'rdinrecord_list';
    
    // 自动写入时间戳字段
   // protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public function rdinrecord()
    {
        return $this->hasOne('\app\admin\model\outhouse\rdinrecord', 'code', 'code');
    }

    public function shelves(){
        return $this->hasOne('\app\common\model\Shelves','id','shelves_id')->field('id,name');
    }

    /**
     * @param $params
     * @param $code  单号
     * @param $createtime
     * @return void
     */
    public static function addDataByBatch($params, $code, $createtime)
    {
        $basic_json    = $params['basic'];
        $basic_arr     = json_decode($basic_json, true);
        foreach ($basic_arr as $k => $v) {
            $list[] = [
                'code' => $code,
                'shelves_id' => $v['shelves_id'],
                'cInvCode' => $v['cInvCode'],
                'iQuantity' => $v['numbers'],
                'createtime' => $createtime,
            ];
        }
        //表体
        Db::name('rdinrecord_list')->insertAll($list);
    }






}
